/**
 * Created by Lwang on 2017/3/22.
 * 修改信息
 */

import {square, ajax} from './resize.js';
import {way} from "./common.js";
import $ from "jquery";
var layer = require("./layer.js");
square(document, window);
$(function () {
    var id = "",
        headImg = "",
        createTime = "",
        openId = "";
    way._login(() => {
        $.ajax({
            url: ajax.teacherInfo,
            xhrFields: {withCredentials: true},
            success: (res) => {
                if (!res.code) {
                    id = res.id;
                    headImg = res.headImg;
                    createTime = res.createTime;
                    openId = res.openId;
                    $(".user-img").find("img").attr("src", res.headImg);
                    $("#nickName").val(res.nickName);
                    $("#nike").val(res.nickName);
                    $("#name").val(res.name);
                    $("#phone").val(res.phone);
                    $("#level").val(res.level);
                    $("#university").val(res.university);
                } else if (res.code == "10000") {

                }

            }
        });
    });

    $("#modify").click(function () {
        layer.open({
            type: 2,
            content: "正在提交中！！"
        });
        $.ajax({
            url: ajax.modifyTeacher,
            type: "POST",
            xhrFields: {withCredentials: true},
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify({
                "course": "string",
                "createTime": createTime,
                "headImg": headImg,
                "id": id,
                "level": $("#level").val(),
                "name": $("#name").val(),
                "nickName": $("#nike").val(),
                "openId": openId,
                "phone": $("#phone").val(),
                "status": "ENABLED",
                "university": $("#university").val()
            }),
            success: (res) => {
                layer.closeAll();
                layer.open({
                    type: 1,
                    content: "修改成功",
                    time:1,
                    success:function () {
                        location.href = "/my-info.html"
                    }
                })
            }
        })
    })
});